package mvc.command.armory
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;

	import flash.display.DisplayObject;

	import iris.managers.IrisPopUpManager;

	import mvc.control.ArmoryEvent;

	import mx.collections.ArrayCollection;
	import mx.core.Application;
	import mx.managers.PopUpManager;

	import nz.co.codec.flexorm.EntityManager;
	import nz.co.codec.flexorm.criteria.Criteria;

	import orm.fantasy.RCharItemVO;
	import orm.fantasy.TblCharacterVO;
	import orm.fantasy.TblItemPropertyVO;
	import orm.fantasy.TblItemVO;

	import view.design.DesignArmoryTip;
	import view.design.DesignCharacter;
	import view.design.DesignSlot;

	import vo.ArmoryBean;

	public class EquipOneSlotCmd implements ICommand
	{
		public function execute(event:CairngormEvent):void
		{
			var armoryBean:ArmoryBean = event.data.armoryBean as ArmoryBean;
			var tblItemVO:TblItemVO = armoryBean.itemVo;
			var tblItemPropVO:TblItemPropertyVO = armoryBean.itemPropertyVo;
			var dsnCharacter:DesignCharacter = Application.application.dsnMain.dsnCharacters.tabCharacters.selectedChild as DesignCharacter;
			var tblCharacterVO:TblCharacterVO = dsnCharacter.tblCharacterVO;
			var em:EntityManager = EntityManager.instance;

			var designSlot:DesignSlot = SearchOptionalItemCmd.dsnSlot;
			// 删除老装备
			if(designSlot.rCharItemVO != null)
				em.remove(designSlot.rCharItemVO);

			// 增加新装备
			var r:RCharItemVO = new RCharItemVO();
			r.tbl_character_id = tblCharacterVO.id;
			r.tbl_item_id = tblItemVO.id;
			em.save(r);
			designSlot.initilaizeArmory(r, tblItemVO, tblItemPropVO);
		}
	}
}